package com.store.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.store.app.R;
import com.store.app.bean.MemberTradRecordBean;

import java.util.List;

/**
 * Created by Ben
 * on 2016/9/1 0001.\
 */
public class MemberTradeRecordAdapter extends BaseAdapter {
    private List<MemberTradRecordBean> memberTradRecordBean;
    private Context context;


    public MemberTradeRecordAdapter(List<MemberTradRecordBean> memberTradRecordBean, Context context) {
        this.memberTradRecordBean = memberTradRecordBean;
        this.context = context;
    }

    @Override
    public int getCount() {
        return memberTradRecordBean.size();
    }

    @Override
    public Object getItem(int position) {
        return memberTradRecordBean.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_trade_record, null);

            viewHolder.item_time = (TextView) convertView.findViewById(R.id.item_time);
            viewHolder.item_acount = (TextView) convertView.findViewById(R.id.item_acount);
            viewHolder.item_type = (TextView) convertView.findViewById(R.id.item_type);
            viewHolder.item_money = (TextView) convertView.findViewById(R.id.item_money);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.item_time.setText(memberTradRecordBean.get(position).getDate()+"");
        viewHolder.item_acount.setText(memberTradRecordBean.get(position).getContact()+"");
        viewHolder.item_type.setText(memberTradRecordBean.get(position).getType()+"");
        viewHolder.item_money.setText(memberTradRecordBean.get(position).getAmount()+"");
        return convertView;
    }
    class ViewHolder {
        private TextView item_time;
        private TextView item_acount;
        private TextView item_type;
        private TextView item_money;
    }
}
